#include "xdemux_task.h"
#include <cstring>
#include <windows.h>
#include <chrono>
#ifdef main
#undef main
#endif // !main
using namespace std;
#define CAM1 "rtsp://17585684163:ZhangHu13356@192.168.137.87:554/live/ch00_"
XDemuxTask *pdet = nullptr;
// 控制台事件处理函数
BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType) {
  switch (dwCtrlType) {
  case CTRL_C_EVENT:
  case CTRL_BREAK_EVENT:
  case CTRL_CLOSE_EVENT:    // 用户点击控制台右上角 ×
  case CTRL_LOGOFF_EVENT:   // 用户注销
  case CTRL_SHUTDOWN_EVENT: // 系统关机
    if (pdet) {
        pdet->Stop()
      return TRUE; // 表示已处理
    }
  default:
    return FALSE;
  }
}
int main(int argc, char *argv[]) {
  // 注册控制台事件处理器
  if (!SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE)) {
    std::cerr << "设置控制台处理器失败！" << std::endl;
    return -1;
  }
  XDemuxTask det;
  pdet = &det;
  for (;;) {
    if (det.Open(CAM1)) {
      break;
    }
    MSleep(100);
    continue;
  }
  det.Start();
  this_thread::sleep_for(10min);
  det.Stop();
  return 0;
}
